package cn.liuxue.lifecircle.page;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import cn.liuxue.lifecircle.R;

public class PageActivity extends Activity implements OnTouchListener, OnLongClickListener{
	private ViewPager pager;
	private List<View> pageviews;
	private ViewGroup main;
	private float currentX;
	private float currentY;
	private ImageView image1;
	private boolean isLongClick;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pageviews = new ArrayList<View>();
        LayoutInflater inflater = getLayoutInflater();
        View imageitem = inflater.inflate(R.layout.imageitem, null);
        image1 = (ImageView)imageitem.findViewById(R.id.img1);
        imageitem.setOnTouchListener(this);
        image1.setOnLongClickListener(this);
        pageviews.add(imageitem);
        pageviews.add(inflater.inflate(R.layout.imageitem2, null));
     
        main = (ViewGroup)inflater.inflate(R.layout.activity_page, null);  
//        pager = (ViewPager)main.findViewById(R.id.guidePages);
        pager.setAdapter(new PageViewAdapter());
        pager.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
        setContentView(main);
    }

    class PageViewAdapter extends PagerAdapter {

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			((ViewPager)arg0).removeView(pageviews.get(arg1));
			
		}

		@Override
		public void finishUpdate(View arg0) {
			// TODO Auto-generated method stub
			
		}
		 

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return pageviews.size();
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			((ViewPager)arg0).addView(pageviews.get(arg1));
			
			return pageviews.get(arg1);
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			// TODO Auto-generated method stub
			return arg0 == arg1;
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public Parcelable saveState() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
			// TODO Auto-generated method stub
			
		}
    	
    }

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
			currentX = event.getX();
			currentY = event.getY();
		}
		if (event.getAction() == MotionEvent.ACTION_UP) {
			isLongClick = false;
		}
		
		return false;
	}

	@Override
	public boolean onLongClick(View v) {
		isLongClick = true;
		return false;
	}
	
	
    
}
